package com.dsbridge.enrollment.web;

import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

import org.springframework.context.ApplicationContext;
import org.springframework.web.jsf.FacesContextUtils;

import com.dsbridge.enrollment.business.CourseBusinessService;
import com.dsbridge.enrollment.entities.CourseAuthor;

@ManagedBean(name="couseControlBean")
@RequestScoped
public class CourseAuthorController {

	private String author;
	private String loginName;
	private String password;
	private String firstName;
	private String middleName;
	private String lastName;
    private String gender;
    private String addressLine1;
    private String addressLine2;
    private String city;
    private String state;
    private String zipcode;
    
    public CourseAuthorController(){
    	genderList=new ArrayList<SelectItem>();
    	SelectItem selectItem=new SelectItem("M","Male");
    	SelectItem selectItemF=new SelectItem("F","FeMale");
    	genderList.add(selectItem);
    	genderList.add(selectItemF);
    	//selectItem.setLabel("Male");
    	//selectItem.setValue("M");
    	
    }
    
    private List<SelectItem> genderList;
    
    public List<SelectItem> getGenderList() {
		return genderList;
	}

	public void setGenderList(List<SelectItem> genderList) {
		this.genderList = genderList;
	}

	public String createAuthor(){
    	CourseAuthor courseAuthor=new CourseAuthor();
    	courseAuthor.setAuthor(author);
    	courseAuthor.setLoginName(loginName);
    	courseAuthor.setPassword(password);
    	courseAuthor.setFirstName(firstName);
    	courseAuthor.setMiddleName(middleName);
    	courseAuthor.setLastName(lastName);
    	courseAuthor.setGender(gender);
    	courseAuthor.setAddressLine1(addressLine1);
    	courseAuthor.setAddressLine2(addressLine2);
    	courseAuthor.setCity(city);
    	courseAuthor.setState(state);
    	courseAuthor.setZipcode(zipcode);
    	
    	ApplicationContext appContext=FacesContextUtils.getRequiredWebApplicationContext(FacesContext.getCurrentInstance());
    	CourseBusinessService courseBusinessService=appContext.getBean(CourseBusinessService.class);
    	int i=courseBusinessService.createAuthor(courseAuthor);
    	if (i > 0) {
			FacesContext.getCurrentInstance().addMessage(
					"AuthorCreateMessage",
					new FacesMessage(FacesMessage.SEVERITY_INFO,
							"Course Author Created Succesfully", "D"));
			return "AuthorResponse";
		} else {
			return "AuthorError";
		}
    }

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getMiddleName() {
		return middleName;
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getAddressLine1() {
		return addressLine1;
	}

	public void setAddressLine1(String addressLine1) {
		this.addressLine1 = addressLine1;
	}

	public String getAddressLine2() {
		return addressLine2;
	}

	public void setAddressLine2(String addressLine2) {
		this.addressLine2 = addressLine2;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getZipcode() {
		return zipcode;
	}

	public void setZipcode(String zipcode) {
		this.zipcode = zipcode;
	}
    
    
}
